home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / awe2-0_1.lha / awe2-0.1 / Src / LowerBoundedFifo.cc < prev    next >
C/C++ Source or Header  |  1990-07-09  |  2KB  |  93 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. // 
  3. // Copyright (C) 1988 University of Illinois, Urbana, Illinois
  4. // Copyright (C) 1989 University of Colorado, Boulder, Colorado
  5. // Copyright (C) 1990 University of Colorado, Boulder, Colorado
  6. //
  7. // written by Dirk Grunwald (grunwald@foobar.colorado.edu)
  8. //
  9. #include "LowerBoundedFifo.h"
  10. #include "CpuMultiplexor.h"
  11. #include "stream.h"
  12. #include "assert.h"
  13.  
  14. LowerBoundedFifo::LowerBoundedFifo(int defaultLength)
  15.     : (defaultLength),
  16.     lowerBoundLock(0, &lowerBoundLockFifo), lowerBoundLockFifo(2)
  17. {
  18.     //
  19.     // do nothing
  20.     //
  21. }
  22.  
  23. void LowerBoundedFifo::add(AwesimeFifoItem *t) {
  24.     LockedFifo::add(t);
  25.     lowerBoundLock.release();
  26. }
  27.  
  28. bool
  29. LowerBoundedFifo::remove(AwesimeFifoItem *item)
  30. {
  31.     (void) lowerBoundLock.reserve();
  32.     bool ok = LockedFifo::remove(item);
  33.     //
  34.     //    The remove had better have worked, or there's something screwy
  35.     //  with the semaphores.
  36.     //
  37.     assert(ok);
  38.     return(ok);
  39. }
  40.  
  41. bool
  42. LowerBoundedFifo::removeNoBlock(AwesimeFifoItem *item)
  43. {
  44.     bool ok = lowerBoundLock.reserveNoBlock();
  45.     if ( ok ) {
  46.     ok = LockedFifo::remove(item);
  47.     }
  48.     return(ok);
  49. }
  50.  
  51. bool
  52. LowerBoundedFifo::removeIfFound(AwesimeFifoItem *item) {
  53.     bool ok = LockedFifo::removeIfFound(item);
  54.     if (ok) {
  55.     (void) lowerBoundLock.reserve();
  56.     }
  57.     return(ok);
  58. }
  59.  
  60. bool
  61. LowerBoundedFifo::doDelete(AwesimeFifoIndex& index) {
  62.     //
  63.     // This is problematic. Since this is a LockedFifo, this person
  64.     // will be the only one with access to the list. If he blocks
  65.     // at this point, he's dead-meat.
  66.     //
  67.     // So, is this an error? If so, should we protect him?
  68.     //
  69.     bool whaHap = AwesimeFifo::doDelete(index);
  70.     if (whaHap) {
  71.     bool noBlock = lowerBoundLock.reserveNoBlock();
  72.     assert( noBlock );
  73.     }
  74.     return(whaHap);
  75. }
  76.  
  77. unsigned int
  78. LowerBoundedFifo::size()
  79. {
  80.     return(AwesimeFifo::size());
  81. }
  82.  
  83. void LowerBoundedFifo::classPrintOn(ostream& s)
  84. {
  85.     s << "[LowerBoundedFifo " ;
  86.     s << "\tSemaphore\n";
  87. //    s << lowerBoundLock;
  88.     s << "\n";
  89.     s << "\tFifo";
  90.     AwesimeFifo::classPrintOn(s);
  91.     s << "\n]\n" ;
  92. }
  93.